<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.2" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="css," />





  <link rel="alternate" href="/atom.xml" title="OBKoro1's Blog" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.1.2" />






<meta name="description" content="写在前面：本文的主要内容包括：type=”range”属性介绍，修改range默认css样式以及在js中的实际应用。本文面向前端小白，写的不好之处，请多多见谅。文末有demo链接，可以自行复制到本地进行试验。 相关：自定义 range radio select的样式滑轮，按钮，选择框 最终要实现的效果： 步骤：1.range属性相关介绍2.搭建html结构；3.css样式修改，包括给滑动轨道添加样">
<meta name="keywords" content="css">
<meta property="og:type" content="article">
<meta property="og:title" content="range滑块自定义样式，步骤详解以及实际应用">
<meta property="og:url" content="http://yoursite.com/2017/10/11/range滑块自定义样式，步骤详解以及实际应用/index.html">
<meta property="og:site_name" content="OBKoro1&#39;s Blog">
<meta property="og:description" content="写在前面：本文的主要内容包括：type=”range”属性介绍，修改range默认css样式以及在js中的实际应用。本文面向前端小白，写的不好之处，请多多见谅。文末有demo链接，可以自行复制到本地进行试验。 相关：自定义 range radio select的样式滑轮，按钮，选择框 最终要实现的效果： 步骤：1.range属性相关介绍2.搭建html结构；3.css样式修改，包括给滑动轨道添加样">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/d6188c82f8938b287a45">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/65f15ffd154ba761c1c5">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/b6e9b9bcc9e0cfb67c33">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/81cefd16c36049964697">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/faf23fe99426e4cb2a3e">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/2d41f7daf7c2e9f145dc">
<meta property="og:image" content="https://dn-mhke0kuv.qbox.me/9cb92093087cfbf62c1f.gif">
<meta property="og:updated_time" content="2019-06-15T06:19:47.634Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="range滑块自定义样式，步骤详解以及实际应用">
<meta name="twitter:description" content="写在前面：本文的主要内容包括：type=”range”属性介绍，修改range默认css样式以及在js中的实际应用。本文面向前端小白，写的不好之处，请多多见谅。文末有demo链接，可以自行复制到本地进行试验。 相关：自定义 range radio select的样式滑轮，按钮，选择框 最终要实现的效果： 步骤：1.range属性相关介绍2.搭建html结构；3.css样式修改，包括给滑动轨道添加样">
<meta name="twitter:image" content="https://dn-mhke0kuv.qbox.me/d6188c82f8938b287a45">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Gemini',
    version: '5.1.2',
    sidebar: {"position":"left","display":"post","offset":12,"offset_float":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/2017/10/11/range滑块自定义样式，步骤详解以及实际应用/"/>





  <title>range滑块自定义样式，步骤详解以及实际应用 | OBKoro1's Blog</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?64d57d0b926bbd27431daa89d2e0a76b";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">OBKoro1's Blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-前端算法">
          <a href="/arithmetic/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-book"></i> <br />
            
            前端算法
          </a>
        </li>
      
        
        <li class="menu-item menu-item-博客最新更新">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            博客最新更新
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br />
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-commonweal">
          <a href="/404/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-heartbeat"></i> <br />
            
            公益404
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/2017/10/11/range滑块自定义样式，步骤详解以及实际应用/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="OBKoro1">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/uploads/hand1.jpg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="OBKoro1's Blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">range滑块自定义样式，步骤详解以及实际应用</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-10-11T22:35:25+08:00">
                2017-10-11
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/css/" itemprop="url" rel="index">
                    <span itemprop="name">css</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          
             <span id="/2017/10/11/range滑块自定义样式，步骤详解以及实际应用/" class="leancloud_visitors" data-flag-title="range滑块自定义样式，步骤详解以及实际应用">
               <span class="post-meta-divider">|</span>
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               
                 <span class="post-meta-item-text">阅读次数&#58;</span>
               
                 <span class="leancloud-visitors-count"></span>
             </span>
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">字数统计&#58;</span>
                
                <span title="字数统计">
                  2,291 字
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">阅读时长 &asymp;</span>
                
                <span title="阅读时长">
                  10分钟
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h2 id="写在前面："><a href="#写在前面：" class="headerlink" title="写在前面："></a>写在前面：</h2><p>本文的主要内容包括：type=”range”属性介绍，修改range默认css样式以及在js中的实际应用。本文面向前端小白，写的不好之处，请多多见谅。文末有demo链接，可以自行复制到本地进行试验。</p>
<p>相关：<a href="https://juejin.im/post/58f1f76e44d904006cf2482d" target="_blank" rel="noopener">自定义 range radio select的样式滑轮，按钮，选择框</a></p>
<h2 id="最终要实现的效果："><a href="#最终要实现的效果：" class="headerlink" title="最终要实现的效果："></a>最终要实现的效果：</h2><p><img src="https://dn-mhke0kuv.qbox.me/d6188c82f8938b287a45" alt="其中包括一部分js代码"></p>
<h2 id="步骤："><a href="#步骤：" class="headerlink" title="步骤："></a>步骤：</h2><h3 id="1-range属性相关介绍"><a href="#1-range属性相关介绍" class="headerlink" title="1.range属性相关介绍"></a>1.range属性相关介绍</h3><h3 id="2-搭建html结构；"><a href="#2-搭建html结构；" class="headerlink" title="2.搭建html结构；"></a>2.搭建html结构；</h3><h3 id="3-css样式修改，包括给滑动轨道添加样式、给滑块添加样式；"><a href="#3-css样式修改，包括给滑动轨道添加样式、给滑块添加样式；" class="headerlink" title="3.css样式修改，包括给滑动轨道添加样式、给滑块添加样式；"></a>3.css样式修改，包括给滑动轨道添加样式、给滑块添加样式；</h3><h3 id="4-添加相关js代码实现应用效果"><a href="#4-添加相关js代码实现应用效果" class="headerlink" title="4.添加相关js代码实现应用效果;"></a>4.添加相关js代码实现应用效果;</h3><h3 id="5-关于浏览器兼容。"><a href="#5-关于浏览器兼容。" class="headerlink" title="5.关于浏览器兼容。"></a>5.关于浏览器兼容。</h3><hr>
<h3 id="在html里面输入如下内容，即可使用："><a href="#在html里面输入如下内容，即可使用：" class="headerlink" title="在html里面输入如下内容，即可使用："></a>在html里面输入如下内容，即可使用：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;input type=&quot;range&quot;&gt;//这是最粗糙的使用方式</span><br></pre></td></tr></table></figure>
<h3 id="range在各个浏览器中的默认样式："><a href="#range在各个浏览器中的默认样式：" class="headerlink" title="range在各个浏览器中的默认样式："></a>range在各个浏览器中的默认样式：</h3><p><img src="https://dn-mhke0kuv.qbox.me/65f15ffd154ba761c1c5" alt=""></p>
<h3 id="range属性相关："><a href="#range属性相关：" class="headerlink" title="range属性相关："></a>range属性相关：</h3><p>range 输入类型用于应该包含指定范围值的输入字段。<br>range 类型显示为滑块。<br>您也可以设置可接受<strong>数字的范围限制：</strong><br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">&lt;input type=&quot;range&quot; name=&quot;points&quot; min=&quot;1&quot; max=&quot;10&quot; /&gt;//max为最大的值，min为最小的值</span><br></pre></td></tr></table></figure></p>
<h3 id="html5-range-类型的限定："><a href="#html5-range-类型的限定：" class="headerlink" title="html5 range 类型的限定："></a>html5 range 类型的限定：</h3><p><img src="https://dn-mhke0kuv.qbox.me/b6e9b9bcc9e0cfb67c33" alt="html5关于range的属性"></p>
<h3 id="HTML-DOM-Input-Range-对象（js获取dom）"><a href="#HTML-DOM-Input-Range-对象（js获取dom）" class="headerlink" title="HTML DOM Input Range 对象（js获取dom）"></a>HTML DOM Input Range 对象（js获取dom）</h3><p><img src="https://dn-mhke0kuv.qbox.me/81cefd16c36049964697" alt="js获取dom可以看看，到时可以查阅相关资料"></p>
<hr>
<h3 id="搭建html结构："><a href="#搭建html结构：" class="headerlink" title="搭建html结构："></a>搭建html结构：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&lt;div class=&quot;js-2-1section3&quot;&gt;</span><br><span class="line">    &lt;div class=&quot;js-2-1section3-div1&quot;&gt;</span><br><span class="line">        &lt;span class=&quot;js-2-1section3-div1-span1&quot;&gt;玩家人数&lt;/span&gt;</span><br><span class="line">        &lt;input type=&quot;text&quot; class=&quot;player-num&quot; id=&quot;player&quot;  value=&quot;6&quot;  max=&quot;18&quot; min=&quot;6&quot; onblur=&quot;on_change()&quot;&gt;</span><br><span class="line">         &lt;!--onblur是当对象失去焦点的时候执行的函数--&gt;</span><br><span class="line">        &lt;span class=&quot;js-2-1section3-div1-span1&quot;&gt;人&lt;/span&gt;</span><br><span class="line">    &lt;/div&gt;&lt;!--上面这部分是玩家人数方框的html--&gt;</span><br><span class="line">    &lt;div class=&quot;js-2-1section3-div2&quot;&gt;</span><br><span class="line">        &lt;button class=&quot;btn-sub&quot; id=&quot;btnSub&quot; onclick=&quot;less()&quot; &gt;&lt;/button&gt;&lt;!--减value的按钮--&gt;</span><br><span class="line">        &lt;input type=&quot;range&quot; class=&quot;slider-block&quot; id=&quot;slider&quot; max=&quot;18&quot; min=&quot;6&quot; step=&quot;1&quot; value=&quot;6&quot; onchange=&quot;moveChange()&quot;&gt;</span><br><span class="line">        &lt;!--onchange是当对象发生变化时执行的函数--&gt;</span><br><span class="line">        &lt;button class=&quot;btn-add&quot; id=&quot;btnAdd&quot;  onclick=&quot;plus()&quot;&gt;&lt;/button&gt;&lt;!--加value的按钮--&gt;</span><br><span class="line">    &lt;/div&gt;</span><br><span class="line">&lt;/div&gt;</span><br></pre></td></tr></table></figure>
<h3 id="解析："><a href="#解析：" class="headerlink" title="解析："></a>解析：</h3><p>1.考虑到文章篇幅，html其他标签自行补全。</p>
<p>2.上面中，代码注释已经注释的很清楚了，<strong>不明白的多看几遍代码</strong>，然后也可以百度一下相关属性之类的。</p>
<p>3.<strong>滑块里面设置value=”6”的作用</strong>是浏览器进入时候滑块在最小值，也就是最左侧的地方，否则默认在中间</p>
<p>4.step=”1”意思是，滑块每次动态改变的数值。</p>
<p>5.关于代码中js部分，<strong>还没学js的小伙伴们，可以跳过，不影响修改滑块的默认样式的。</strong></p>
<p><img src="https://dn-mhke0kuv.qbox.me/faf23fe99426e4cb2a3e" alt="再放一下最终实现的效果，省的翻页麻烦"></p>
<h3 id="css样式修改："><a href="#css样式修改：" class="headerlink" title="css样式修改："></a>css样式修改：</h3><p>下面是玩家人数的css样式（不重要，可以跳过）：<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line">body&#123;</span><br><span class="line">    width: 50%;</span><br><span class="line">    margin:5rem auto 0;</span><br><span class="line">&#125;</span><br><span class="line">div&#123;</span><br><span class="line">    margin: 2rem;</span><br><span class="line">&#125;</span><br><span class="line">.js-2-1section3&#123;</span><br><span class="line">    background: #fff;&#125;</span><br><span class="line">.js-2-1section3-div1&#123;</span><br><span class="line">    margin-left: 2rem;&#125;</span><br><span class="line">.player-num&#123;</span><br><span class="line">    font-size: 1.8rem;</span><br><span class="line">    margin:0 0.6rem;</span><br><span class="line">    background: #f4f5f5;</span><br><span class="line">    padding: 0.2rem 0.6rem;</span><br><span class="line">    color: gold;</span><br><span class="line">    width: 9%;</span><br><span class="line">    border: none;</span><br><span class="line">    outline: none;</span><br><span class="line">&#125;</span><br><span class="line">span&#123;</span><br><span class="line">    display: inline-block;</span><br><span class="line">    font-size: 1.8rem;</span><br><span class="line">    color: #444;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">.js-2-1section3-div2&#123;</span><br><span class="line">    display: flex;</span><br><span class="line">    justify-content: space-around;</span><br><span class="line">    align-items: center;</span><br><span class="line">    padding: 1.6rem 0;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">/*上面是玩家人数的css样式*/</span><br></pre></td></tr></table></figure></p>
<h3 id="修改滑块样式的css代码-重点-："><a href="#修改滑块样式的css代码-重点-：" class="headerlink" title="修改滑块样式的css代码(重点)："></a>修改滑块样式的css代码(重点)：</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line">    #slider&#123; /*设置滑块下面那条线的样式*/</span><br><span class="line">        outline: none; /*去掉点击时出现的外边框*/</span><br><span class="line">        -webkit-appearance: none;</span><br><span class="line">        -moz-appearance: none;</span><br><span class="line">        appearance: none; /*这三个是去掉那条线原有的默认样式，划重点！！*/</span><br><span class="line">        width: 30%;</span><br><span class="line">        height: 0.3rem;</span><br><span class="line">        background: orange;</span><br><span class="line">        /*这三个是设置滑块下面那条线的样式*/</span><br><span class="line">    &#125;</span><br><span class="line">    input[type=&quot;range&quot;]::-webkit-slider-thumb &#123;</span><br><span class="line">        /*::-webkit-slider-thumb是代表给滑块的样式进行变更*/</span><br><span class="line">        -webkit-appearance: none;</span><br><span class="line">        -moz-appearance: none;</span><br><span class="line">        appearance: none; /*//这三个是去掉滑块原有的默认样式，划重点！！*/</span><br><span class="line">        -webkit-box-shadow:0 0 2px ; /*设置滑块的阴影*/</span><br><span class="line">        width: 2.6rem;</span><br><span class="line">        height:1.6rem;</span><br><span class="line">        background: url(&quot;images/js2-d_03.png&quot;);</span><br><span class="line">        background-size: cover;</span><br><span class="line">        /*//这几个是设置滑块的样式*/</span><br><span class="line">    &#125;</span><br><span class="line">    &lt;!--上面是修改滑块和滑块轨道的样式，下面是左右两边按钮的css样式--&gt;</span><br><span class="line"></span><br><span class="line">    .btn-sub&#123; /*这里是左边减按钮的css样式*/</span><br><span class="line">        outline: none;</span><br><span class="line">        border: none;</span><br><span class="line">        cursor: pointer;</span><br><span class="line">        background: url(&quot;images/js2-f_03.png&quot;);</span><br><span class="line">        background-size: 100%;</span><br><span class="line">        width: 1.8rem;</span><br><span class="line">        height: 1.8rem;</span><br><span class="line">    &#125;</span><br><span class="line">    .btn-add&#123; /*这里是右边+按钮的css样式*/</span><br><span class="line">        outline: none;</span><br><span class="line">        border: none;</span><br><span class="line">        cursor: pointer;</span><br><span class="line">        background: url(&quot;images/js2-e_03.png&quot;) no-repeat;</span><br><span class="line">        background-size: 100%;</span><br><span class="line">        width: 1.8rem;</span><br><span class="line">        height: 1.8rem;</span><br><span class="line">    &#125;</span><br><span class="line">&lt;!--css代码写的有点乱，见谅啊。--&gt;</span><br></pre></td></tr></table></figure>
<h3 id="解析：-1"><a href="#解析：-1" class="headerlink" title="解析："></a>解析：</h3><p>1.代码注释里面已经很清楚了，不清楚多看几遍代码。<br>2.文末有demo链接，可以自行复制到本地进行试验。</p>
<p>以上是修改css样式到上面放的图片效果。</p>
<hr>
<h2 id="扩展：使用js完成实际应用"><a href="#扩展：使用js完成实际应用" class="headerlink" title="扩展：使用js完成实际应用"></a>扩展：使用js完成实际应用</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">  var oPlayerNum = document.getElementById(&quot;player&quot;);//玩家总人数</span><br><span class="line">var osliderBlock = document.getElementById(&quot;slider&quot;);//滑块的值</span><br><span class="line">function on_change() &#123;</span><br><span class="line">    if (oPlayerNum.value &gt;= 6 &amp;&amp; oPlayerNum.value &lt;= 18) &#123;//设置方框里面玩家人数范围</span><br><span class="line">        osliderBlock.value=oPlayerNum.value ;//将玩家总人数赋值给滑块的值，实现动态变化</span><br><span class="line">    &#125; else &#123;</span><br><span class="line">        alert(&quot;请输入正确的人数6~18&quot;);</span><br><span class="line">        oPlayerNum.value=6;</span><br><span class="line">        osliderBlock.value=6;</span><br><span class="line">//人数超出范围的话，弹出警告框，并且将方框和滑块的值重置为6</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">function moveChange() &#123;// 滑块的值改变，运行这个函数</span><br><span class="line">    oPlayerNum.value=osliderBlock.value;</span><br><span class="line">    //滑块的值改变的话，滑块的值赋值给方框，实现动态变化</span><br><span class="line">&#125;</span><br><span class="line">function less() &#123;</span><br><span class="line">    oPlayerNum.value--;</span><br><span class="line">    //减的按钮，减掉玩家总人数的值</span><br><span class="line">    if (oPlayerNum.value&lt;6)&#123;</span><br><span class="line">        alert(&quot;人太少了，再找几个小伙伴来吧&quot;);</span><br><span class="line">        oPlayerNum.value=6;</span><br><span class="line">        //人数超出范围的话，弹出警告框，并且将方框和滑块的值重置为6</span><br><span class="line">    &#125;</span><br><span class="line">    else &#123;</span><br><span class="line">        osliderBlock.value=oPlayerNum.value;// 将玩家人数赋值给滑轮的值</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br><span class="line">function plus() &#123;</span><br><span class="line">    oPlayerNum.value++;</span><br><span class="line">    //加的按钮，减掉玩家总人数的值，上面的值已经相互关联了，所以方框的值改变，滑块的值也会改变</span><br><span class="line">    if (oPlayerNum.value&gt;18)&#123;</span><br><span class="line">        alert(&quot;人太多了，可以分一批人再开一局&quot;);</span><br><span class="line">        oPlayerNum.value=18;</span><br><span class="line">        //人数超出范围的话，弹出警告框，并且将方框和滑块的值重置为18</span><br><span class="line">    &#125;</span><br><span class="line">    else &#123;</span><br><span class="line">        osliderBlock.value=oPlayerNum.value;// 将玩家人数赋值给滑轮的值</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>
<p>ps：<br>1.特地重新再打一遍注释，注释里面说的蛮清楚了，还没学js的小伙伴别灰心，先mark起来，等以后学会了，再回头看看。<br>2.文末有demo链接，可以自行复制到本地进行试验。</p>
<h3 id="关于浏览器兼容的问题：还未完成的效果，滑块填充效果。"><a href="#关于浏览器兼容的问题：还未完成的效果，滑块填充效果。" class="headerlink" title="关于浏览器兼容的问题：还未完成的效果，滑块填充效果。"></a>关于浏览器兼容的问题：还未完成的效果，滑块填充效果。</h3><p>ps：关于浏览器兼容这块儿，还没研究好（下面有篇文章是讲<strong>浏览器兼容</strong>的）。<strong>以上只针对谷歌浏览器</strong>，因为range是html5新出的属性，w3c还没出标准属性，各个浏览器的方法不一样，这块儿有点麻烦。但我记在笔记里面了，今后研究清楚了，再回来更文。</p>
<p><img src="https://dn-mhke0kuv.qbox.me/2d41f7daf7c2e9f145dc" alt="三个浏览器的不同效果"><br>关于滑块的填充效果，各个浏览器都不一样<strong>Chrome</strong>浏览器中不支持直接设置进度条，要借助js。而在IE 9以上的浏览器中可以使用::-ms-fill-lower 和 ::-ms-fill-upper来自定义进度条；在Firefox浏览器中则可以通过::-moz-range-progress来自定义；今天下午研究了一阵子，只弄出了一个ie的填充效果，没研究清楚，可能过段时间会再回来更新。（有兴趣的小伙伴可以研究一下，相互交流交流。）</p>
<p><img src="https://dn-mhke0kuv.qbox.me/9cb92093087cfbf62c1f.gif" alt="IE演示的"></p>
<h4 id="以下是I兼容E浏览器的滑块"><a href="#以下是I兼容E浏览器的滑块" class="headerlink" title="以下是I兼容E浏览器的滑块"></a>以下是I兼容E浏览器的滑块</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">/*以下是I兼容E浏览器的滑块，还有一些问题，不过现在没空再弄了。等到有空了再解决清楚。*/</span><br><span class="line">      input[type=range]::-ms-fill-lower &#123;//::-ms-fill-lower这是ie兼容range的属性写法下面那个同理</span><br><span class="line">          /*进度条已填充的部分*/</span><br><span class="line">          height: 22px;</span><br><span class="line">          border-radius: 10px;</span><br><span class="line">          /*background: black;*/</span><br><span class="line">          background: linear-gradient(to right, #059CFA, white 100%, white);</span><br><span class="line">      &#125;</span><br><span class="line"></span><br><span class="line">      input[type=range]::-ms-fill-upper &#123;</span><br><span class="line">          /*进度条未填充的部分*/</span><br><span class="line">          height: 22px;</span><br><span class="line">          border-radius: 10px;</span><br><span class="line">          background: red;</span><br><span class="line">      &#125;</span><br></pre></td></tr></table></figure>
<p>这里有篇关于range的文章，里面有<strong>浏览器兼容</strong>的内容，我没弄清楚：<a href="http://blog.csdn.net/u013347241/article/details/51560290" target="_blank" rel="noopener">自定义(滑动条)input[type=”range”]样式</a></p>
<p><strong>range-demo链接</strong>：<a href="https://obkoro1.github.io/article-demo/diy-style/range-diy.html" target="_blank" rel="noopener">https://obkoro1.github.io/article-demo/diy-style/range-diy.html</a></p>
<h2 id="后话："><a href="#后话：" class="headerlink" title="后话："></a>后话：</h2><p>昨天说好的要详细更新，range、radio、select这三类的文章，今天如约更好了range部分，后面几天应该还会持续更文。不说了，要打球去了^_^。</p>
<p><strong>最后：</strong>希望看完的朋友点个<strong>喜欢</strong>，也可以<strong>关注</strong>一下我，现在这阶段基本上每个月都不会少于十五篇文章（看到干货我也会进行分享）。写的不好之处，欢迎指点。码字不易，感谢支持！<br><strong>ps</strong>：目前待业，坐标北京，求推荐工作。然后希望我写哪方面的文章可以在底下评论，或者是私信我，虽然写的不好，但我就当这是记录自己成长的一种方式咯。（前提是我会了，如果不会我也会记下来，等会了的时候再更出来。）<br><a href="http://www.jianshu.com/u/8d1dd8c80f06" target="_blank" rel="noopener"></a><strong><a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" rel="noopener">掘金个人主页</a>  ，</strong><a href="http://www.jianshu.com/u/8d1dd8c80f06" target="_blank" rel="noopener"><strong>简书主页链接</strong></a>，<strong><a href="http://blog.csdn.net/OBKoro1?skin=dark1" target="_blank" rel="noopener">csdn博客主页链接</a> ，<a href="https://github.com/OBKoro1" target="_blank" rel="noopener">github</a> 。</strong></p>
<p>以上。2017.4.16</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>听说，打赏我的人最后都找到了真爱。</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/pay/weixin.jpg" alt="OBKoro1 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/pay/ali.jpg" alt="OBKoro1 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/css/" rel="tag"><i class="fa fa-tag"></i> css</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2017/10/11/干货-css自定义-range-radio-select的样式滑轮，按钮，选择框/" rel="next" title="(干货)css自定义 range  radio select的样式滑轮，按钮，选择框">
                <i class="fa fa-chevron-left"></i> (干货)css自定义 range  radio select的样式滑轮，按钮，选择框
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/10/11/关于js、jq零碎知识点/" rel="prev" title="关于js、jq零碎知识点">
                关于js、jq零碎知识点 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  <div class="comments" id="comments">
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          
            <img class="site-author-image" itemprop="image"
              src="/uploads/hand1.jpg"
              alt="OBKoro1" />
          
            <p class="site-author-name" itemprop="name">OBKoro1</p>
            <p class="site-description motion-element" itemprop="description">种一棵树最好的时间是十年前,其次是现在</p>
        </div>

        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
            
              <a href="/archives">
            
                <span class="site-state-item-count">105</span>
                <span class="site-state-item-name">日志</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              <a href="/categories/index.html">
                <span class="site-state-item-count">20</span>
                <span class="site-state-item-name">分类</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              <a href="/tags/index.html">
                <span class="site-state-item-count">74</span>
                <span class="site-state-item-name">标签</span>
              </a>
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/OBKoro1" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>GitHub</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://juejin.im/user/58714f0eb123db4a2eb95372" target="_blank" title="掘金">
                  
                    <i class="fa fa-fw fa-globe"></i>掘金</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://obkoro1.com/web_accumulate/" target="_blank" title="前端积累">
                  
                    <i class="fa fa-fw fa-globe"></i>前端积累</a>
              </span>
            
              <span class="links-of-author-item">
                <a href="https://segmentfault.com/u/obkoro1/articles" target="_blank" title="segmentfault">
                  
                    <i class="fa fa-fw fa-globe"></i>segmentfault</a>
              </span>
            
          
        </div>

        
        

        
        

        


      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#写在前面："><span class="nav-number">1.</span> <span class="nav-text">写在前面：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#最终要实现的效果："><span class="nav-number">2.</span> <span class="nav-text">最终要实现的效果：</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#步骤："><span class="nav-number">3.</span> <span class="nav-text">步骤：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#1-range属性相关介绍"><span class="nav-number">3.1.</span> <span class="nav-text">1.range属性相关介绍</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#2-搭建html结构；"><span class="nav-number">3.2.</span> <span class="nav-text">2.搭建html结构；</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#3-css样式修改，包括给滑动轨道添加样式、给滑块添加样式；"><span class="nav-number">3.3.</span> <span class="nav-text">3.css样式修改，包括给滑动轨道添加样式、给滑块添加样式；</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#4-添加相关js代码实现应用效果"><span class="nav-number">3.4.</span> <span class="nav-text">4.添加相关js代码实现应用效果;</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#5-关于浏览器兼容。"><span class="nav-number">3.5.</span> <span class="nav-text">5.关于浏览器兼容。</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在html里面输入如下内容，即可使用："><span class="nav-number">3.6.</span> <span class="nav-text">在html里面输入如下内容，即可使用：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#range在各个浏览器中的默认样式："><span class="nav-number">3.7.</span> <span class="nav-text">range在各个浏览器中的默认样式：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#range属性相关："><span class="nav-number">3.8.</span> <span class="nav-text">range属性相关：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#html5-range-类型的限定："><span class="nav-number">3.9.</span> <span class="nav-text">html5 range 类型的限定：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#HTML-DOM-Input-Range-对象（js获取dom）"><span class="nav-number">3.10.</span> <span class="nav-text">HTML DOM Input Range 对象（js获取dom）</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#搭建html结构："><span class="nav-number">3.11.</span> <span class="nav-text">搭建html结构：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解析："><span class="nav-number">3.12.</span> <span class="nav-text">解析：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#css样式修改："><span class="nav-number">3.13.</span> <span class="nav-text">css样式修改：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#修改滑块样式的css代码-重点-："><span class="nav-number">3.14.</span> <span class="nav-text">修改滑块样式的css代码(重点)：</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#解析：-1"><span class="nav-number">3.15.</span> <span class="nav-text">解析：</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#扩展：使用js完成实际应用"><span class="nav-number">4.</span> <span class="nav-text">扩展：使用js完成实际应用</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#关于浏览器兼容的问题：还未完成的效果，滑块填充效果。"><span class="nav-number">4.1.</span> <span class="nav-text">关于浏览器兼容的问题：还未完成的效果，滑块填充效果。</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#以下是I兼容E浏览器的滑块"><span class="nav-number">4.1.1.</span> <span class="nav-text">以下是I兼容E浏览器的滑块</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#后话："><span class="nav-number">5.</span> <span class="nav-text">后话：</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy;  2017 &mdash; 
  <span itemprop="copyrightYear">2019</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">OBKoro1</span>

  
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
    
      <span class="post-meta-item-text">Site words total count&#58;</span>
    
    <span title="Site words total count">
      156.0k
    </span>
  
</div>




<div>
<script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<span class="site-uv"><i class="fa fa-user"></i> 访问用户： <span class="busuanzi-value" id="busuanzi_value_site_uv">21621</span> 人 </span>
<span class="site-pv"><i class="fa fa-eye"></i> 访问次数： <span class="busuanzi-value" id="busuanzi_value_site_pv">68503</span> 次</span>

</div>



        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.2"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.1.2"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.2"></script>



  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.2"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.2"></script>


  

  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.2"></script>



  


  




	





  





  








  



  





  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script>
  <script>AV.initialize("9ANFp60h6oVyxIPGlau3NOA4-gzGzoHsz", "tMdNuKMbFtN4QsekeNVu83TV");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  

  

  

  

  

</body>
</html>

